/**
 * @(#) popOtherSubtractionMediator.as
 *
 * @date		2009. 04. 20.
 * @version		1.0
 * @author		Jo, ChangHun
 * @description	연말정산 메인 view - Mediator
 * 				연말정산 - 탭11 기타소득공제 팝업 Presentation Logic을 관리 
 */
package com.skt.common_hr.yearadjustment.view
{
	import com.skt.common_hr.common.PsHrAlert;
	import com.skt.common_hr.common.Variables;
	import com.skt.common_hr.yearadjustment.YearAdjustmentFacade;
	import com.skt.common_hr.yearadjustment.model.CreditCardProxy;
	import com.skt.common_hr.yearadjustment.model.vo.CreditCardVO;
	import com.skt.common_hr.yearadjustment.view.components.popCreditCard;
	import com.skt.common_hr.yearadjustment.view.components.popOtherSubtraction;
	
	import flash.events.Event;
	
	import mx.managers.PopUpManager;
	
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.patterns.mediator.Mediator;
	
	

	public class popCreditCardMediator extends Mediator
	{
		public static const NAME:String = "popCreditCardMediator"; 
		public var v_year:String = "";
		[Bindable] public var v_enable:Boolean = true;		
	

		/**
		* 생성자
		* 
		* @param
		* @return void
		*/
        public function popCreditCardMediator( viewComponent:Object )
        {
            super( NAME, viewComponent );
            view.callLater(initView);
        }
 		
		/**
		* View를 초기화 한다.
		*	- View에 기본사항을 출력하고 data를 load
		* @param
		* @return void
		*/
 		public function initView():void
 		{
 			view.addEventListener(popOtherSubtraction.OkInput, onOkInput);
  			view.addEventListener(popCreditCard.CancelInput, onCancelInput);
			view._isEnable = v_enable;
 			loadCreditCardList();
 		}
 		
 		private function loadCreditCardList():void{
 			var proxy:CreditCardProxy = facade.retrieveProxy(CreditCardProxy.NAME) as CreditCardProxy;
 			proxy.load(Variables.yearPernr, v_year);
 		}
 		
 		private function onOkInput(event:Event):void{
 			
 		 	var proxy:CreditCardProxy = facade.retrieveProxy(CreditCardProxy.NAME) as CreditCardProxy;
 			
 			var detailList:Array = new Array();
	 		for each(var rec:CreditCardVO in view.creditCardList)
	 		{
	 			detailList.push(rec);
	 		}
 			proxy.save(Variables.yearPernr, v_year, detailList);
 		}
 		
		private function onCancelInput(event:Event):void
 		{
 			facade.removeMediator(popCreditCardMediator.NAME);
 			PopUpManager.removePopUp(view);
 		}
 		

		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Process MVC Messages
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		* 본 Class에서 처리해야할 Noti들을 등록한다.
		* 
		* @param
		* @return void
		*/
		override public function listNotificationInterests():Array 
		{
			return [
					CreditCardProxy.LOAD_CREDITCARD_COMPLETE,
					CreditCardProxy.LOAD_CREDITCARD_FAILED,
					CreditCardProxy.SAVE_CREDITCARD_COMPLETE,
					CreditCardProxy.SAVE_CREDITCARD_FAILED
					];
		}
		

		/**
		* Noti별로 처리한다.
		* 
		* @param
		* @return void
		*/
		override public function handleNotification(note:INotification):void
		{
			switch(note.getName()) 
			{
				case CreditCardProxy.LOAD_CREDITCARD_COMPLETE:
					trace("YearAdjustmentFacade.LOAD_OTHER_LIST_COMPLETE");
					view.creditCardList = (note.getBody() as CreditCardProxy).creditCardList;
					break;
				case CreditCardProxy.LOAD_CREDITCARD_FAILED:
					trace("YearAdjustmentFacade.LOAD_OTHER_LIST_FAILED");
					break;	
				case CreditCardProxy.SAVE_CREDITCARD_COMPLETE:
					trace("YearAdjustmentFacade.SAVE_OTHER_LIST_COMPLETE");
					//regMediator();
					facade.sendNotification(YearAdjustmentFacade.RELOAD_BASIC_DATA);
					onCancelInput(null);
					break;
				case CreditCardProxy.SAVE_CREDITCARD_FAILED:
					PsHrAlert.showMessage((note.getBody() as CreditCardProxy).msgStr);
					trace("YearAdjustmentFacade.SAVE_OTHER_LIST_FAILED");
					break;	
				default:
					//trace(this.instanceID+"에서 처리 안된 Noti가 검출됨 : " + note.getBody());
					break;
			}
		}
 		
		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Utility Functions
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
        private function get view():popCreditCard
        {
            return viewComponent as popCreditCard;
        }
	}
}